package team.knowers.qzh.qzhserver.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import team.knowers.qzh.qzhserver.common.convention.result.Result;
import team.knowers.qzh.qzhserver.common.convention.result.Results;
import team.knowers.qzh.qzhserver.dto.req.PageSubjectCourseReqDTO;
import team.knowers.qzh.qzhserver.dto.req.SetAsMySubjectReqDTO;
import team.knowers.qzh.qzhserver.dto.resp.CourseSimpleRespDTO;
import team.knowers.qzh.qzhserver.dto.resp.ListSubjectsRespDTO;
import team.knowers.qzh.qzhserver.dto.resp.SubjectDetailsRespDTO;
import team.knowers.qzh.qzhserver.service.MySubjectService;
import team.knowers.qzh.qzhserver.service.SubjectService;

import java.util.List;

/**
 * 专业控制层
 *
 * @author xtg
 */
@RestController
@RequiredArgsConstructor
public class SubjectController {
    private final SubjectService subjectService;
    private final MySubjectService mySubjectService;

    /**
     * 展示专业的简略信息：图标，名称，id
     */
    @GetMapping("/api/qzh-server/admin/v1/subject/listSubjects")
    public Result<List<ListSubjectsRespDTO>> listSubjects() {
        return Results.success(subjectService.listSubjects());
    }

    /**
     * 展示单个专业的详细信息
     */
    @GetMapping("/api/qzh-server/admin/v1/subject/listSubjects/{subjectId}")
    public Result<SubjectDetailsRespDTO> subjectDetails(@PathVariable("subjectId") Long subjectId) {
        return Results.success(subjectService.subjectDetails(subjectId));
    }

    /**
     * 某用户设置某专业为我的专业
     */
    @PostMapping("/api/qzh-server/admin/v1/subject/setMySubject")
    public Result<Boolean> setAsMySubject(@RequestBody SetAsMySubjectReqDTO reqDTO) {
        return Results.success(mySubjectService.setSubjectAsMySubject(reqDTO));
    }

    /**
     * 某专业是否被某用户关注
     */
    @GetMapping("/api/qzh-server/admin/v1/subject/isMySubject")
    public Result<Boolean> isMySubject(@RequestParam("username") String username, @RequestParam("subjectId") Long subjectId) {
        return Results.success(mySubjectService.isMySubject(username, subjectId));
    }

    /**
     * 获取某用户的专业
     */
    @GetMapping("/api/qzh-server/admin/v1/subject/getMySubject")
    public Result<Long> getMySubject(@RequestParam("username") String username) {
        return Results.success(mySubjectService.getUserSubject(username));
    }

    /**
     * 按最新发布时间 分页展示该课程专业
     */
    @GetMapping("/api/qzh-server/admin/v1/subject/course")
    public Result<IPage<CourseSimpleRespDTO>> pageSubjectCourseByTimeDesc(PageSubjectCourseReqDTO reqDTO) {
        return Results.success(subjectService.pageSubjectCourseByTimeDesc(reqDTO));
    }
    /**
     * 按销量 分页展示该课程专业
     */
    @GetMapping("/api/qzh-server/admin/v1/subject/course/sales")
    public Result<IPage<CourseSimpleRespDTO>> pageSubjectCourseBySalesVolumeDesc(PageSubjectCourseReqDTO reqDTO) {
        return Results.success(subjectService.pageSubjectCourseBySalesVolumeDesc(reqDTO));
    }

}
